const port = process.env.port || process.env.npm_config_port || 8086// dev port
const path = require('path');
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']

const webpack = require('webpack')

function resolve(dir) {
  return path.join(__dirname, dir)
}

let name = 'wafa-sign-web'




module.exports = {

  publicPath: process.env.NODE_ENV === "development" ? "/" : "/",
  outputDir: 'financial-platform-web',
  lintOnSave: false,
  productionSourceMap: false, // 清除 .map 文件
  css: {
    loaderOptions: {
      less: { javascriptEnabled: true },

    }
  },
  runtimeCompiler: true,
  pwa: {

    iconPaths: {

      favicon32: 'favicon.ico',

      favicon16: 'favicon.ico',

      appleTouchIcon: 'favicon.ico',

      maskIcon: 'favicon.ico',

      msTileImage: 'favicon.ico'

    }

  },
  chainWebpack(config) {
    // set svg-sprite-loader
    config.resolve.alias
      .set("@", resolve("src"))
    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons'))
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()

  },
  transpileDependencies: [
    // 'ant-design-vue',
    'vue-puzzle-vcode',
    /[/\\]node_modules[/\\]_js-base64@3.6.0@js-base64[/\\]/,
  ],
  configureWebpack: {
    // name: 'wafa-sign-web',
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    plugins: [

      // 压缩为gzip
      new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
        threshold: 10240,
        minRatio: 0.8
      }),
      new webpack.optimize.LimitChunkCountPlugin({
        maxChunks: 5,
        minChunkSize: 100
      })
    ],
    output: {
      library: `${name}-[name]`,
      libraryTarget: 'umd', // 把微应用打包成 umd 库格式
      jsonpFunction: `webpackJsonp_${name}`,
    },

  },

  devServer: {
    port: port,
    proxy: {
      // 配置代理
      "/api": {

          //贷款审核接口
          target: 'http://192.168.1.145:8861/',
          //贷款申请
          // target: "http://192.168.1.187:8851/",

          changeOrigin: true,
          pathRewrite: {
              '^/api': ''
          }
      },

    },
    headers:{
      'Access-Control-Allow-Origin':'*'
    }

  }
}
